package cn.itcast.dubbo.controller;

import cn.itcast.dubbo.pojo.Employee;
import cn.itcast.dubbo.service.EmpService;
import cn.itcast.dubbo.util.GlobalConstant;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * @author Hujf
 * @title: EmpController
 * @description: TODO
 * @date 2020/7/22 0022上午 9:48
 */

@RestController
@RequestMapping(value = "/emp")
public class EmpController {

    @Reference(version = "1.0.0")
    private EmpService empService;

    @PostMapping(value = "/login")
    public int login(HttpServletRequest request, @RequestParam("name") String name, @RequestParam("password") String password) {

        HttpSession session = request.getSession();
        Employee employee =empService.findEmpByCondition(new Employee(name));
        if(employee!=null &&employee.getPassword().equals(password)){
            session.setAttribute("emp", employee);
            return GlobalConstant.SUCCESS;
        }
        return GlobalConstant.ERROR;
    }

}
